//
// IOQueue.h
// Usage: Not finished IRP queue
// CreateDate: 2009-06-04
// Author: MaJiuyue
//
#ifndef _IOQUEUE_H_
#define _IOQUEUE_H_

#include <string.h>
#include <RequestPackage.h>

#define MAX_IO_QUEUE	128

class CIOQueue
{
private:
	RequestPackage IOQueue[MAX_IO_QUEUE];
	int head, tail, size;

public:
	CIOQueue()
	{
		head = tail = size = 0;
	}

	bool AddRequest(const RequestPackage * IRP)
	{
		if(size<MAX_IO_QUEUE)
		{
			memcpy(&IOQueue[tail], IRP, sizeof(RequestPackage));
			tail = (tail+1)%MAX_IO_QUEUE;
			size++;
			return true;
		}
		else
		{
			return false;
		}
	}
	bool GetRequest(RequestPackage ** IRP)
	{
		if(size==0)
			return false;
		*IRP = &IOQueue[head];
		return true;
	}

	void RemoveRequest()
	{
		if(size<=0)
			return;

		head = (head+1)%MAX_IO_QUEUE;
		size--;
	}
};

#endif

